home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / pilot-undelete.PL < prev    next >
Text File  |  1997-08-08  |  1KB  |  60 lines

  1. use Config;
  2. print $Config{startperl}, "\n";
  3. print <DATA>;
  4. __DATA__;
  5.  
  6. use PDA::Pilot;
  7. use Getopt::Std;
  8.  
  9. $opts{p} = $ENV{PILOTPORT} if length $ENV{PILOTPORT};
  10.  
  11. if (not getopts('p:d:',\%opts) or not exists $opts{p} or not exists $opts{d}) {
  12.     print "Usage: $0 -p port -d dbname\n";
  13.     print "\n  $0 will scan through dbname on your Pilot and turn all archived\n";
  14.     print "  records into normal records, thus \"undeleting\" them.\n";
  15.     exit;
  16. }
  17.  
  18. $socket = PDA::Pilot::openPort($opts{p});
  19.  
  20. print "Please start HotSync on port $opts{p} now.\n";
  21.  
  22. $dlp = PDA::Pilot::accept($socket);
  23.  
  24. if (defined $dlp) {
  25.     print "\nConnection established. Opening $opts{d}...\n";
  26.     
  27.     $dlp->getStatus;
  28.     
  29.     $db = $dlp->open($opts{d}, "rwsx");
  30.     
  31.     if (defined $db) {
  32.         print "\nDatabase opened.\n";
  33.         
  34.         $i = 0;
  35.         $c = 0;
  36.         for(;;) {
  37.             $r = $db->getRecord($i);
  38.             last if not defined($r); #no more records
  39.             if ($r->{archived}) {
  40.                 print "Record $i is archived, un-archiving.\n";
  41.                 $r->{archived} = 0;
  42.                 $r->{deleted} = 0;
  43.                 $db->setRecord($r); # Re-store record
  44.                 
  45.                 $c++;
  46.             }
  47.             $i++;
  48.         }
  49.         
  50.         $db->close;
  51.         print "Done. $c record", ($c == 1 ? "" : "s"), " unarchived.\n";
  52.     } else {
  53.         print "Unable to open database\n";
  54.     }
  55.     
  56.     $dlp->close;
  57. }
  58. PDA::Pilot::close($socket);
  59. exit(0);
  60.